package com.yunfatong.evidence.service;

import com.yunfatong.evidence.form.contract.AddContractFileInfoForm;
import com.yunfatong.evidence.form.contract.AddContractInfoForm;
import com.yunfatong.evidence.form.contract.AddContractUserInfoForm;
import com.yunfatong.evidence.mapper.EvidenceContractFileInfoMapperCustom;
import com.yunfatong.evidence.mapper.EvidenceContractInfoMapperCustom;
import com.yunfatong.evidence.mapper.EvidenceContractUserInfoMapperCustom;
import com.yunfatong.evidence.model.EvidenceContractFileInfo;
import com.yunfatong.evidence.model.EvidenceContractInfo;
import com.yunfatong.evidence.model.EvidenceContractUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 合同用户service
 */
@Service
public class EvidenceContractUserInfoService {
    //合同中人信息
    @Autowired
    private EvidenceContractUserInfoMapperCustom evidenceContractUserInfoMapperCustom;

    //合同文件信息
    @Autowired
    private EvidenceContractFileInfoMapperCustom evidenceContractFileInfoMapperCustom;

    //合同信息
    @Autowired
    private EvidenceContractInfoMapperCustom evidenceContractInfoMapperCustom;

    /**
     * 新增用户存证接口
     * 说明：存合同中的人的信息
     *
     * @param applyInfo
     * @author liran
     */
    public EvidenceContractUserInfo addContractUserInfo(AddContractUserInfoForm applyInfo) {
        EvidenceContractUserInfo record = new EvidenceContractUserInfo();
        record.setUserMasterId(applyInfo.getUserMasterId());
        record.setUserSlaveId(applyInfo.getUserSlaveId());
        record.setBusinessTypeId(applyInfo.getBusinessId());
        record.setEvidenceType(applyInfo.getEvidenceType());

        record.setJsonHash(applyInfo.getContentHash());
        record.setJsonMd5(applyInfo.getContentMd5());
        record.setJsonSha1(applyInfo.getContentSha1());
        record.setJsonSha256(applyInfo.getContentSha256());
        record.setUserUuid(applyInfo.getUserUuid());
        record.setSize(applyInfo.getSize());
        record.setRecordTime(applyInfo.getRecordTime());
        //是否申请出证： 是否申请出证：0未申请，1申请中，2出证中，3出证完成
        record.setIsApplyEvidence(0);
        record.setStoreEvidenceTime(new Date());
        evidenceContractUserInfoMapperCustom.insertSelective(record);
        return record;
    }

    /**
     * 新增合同文件存证接口 (存合同文件的信息)
     *
     * @param applyInfo
     * @return
     * @author liran
     */
    public EvidenceContractFileInfo addContractFileInfo(AddContractFileInfoForm applyInfo) {
        EvidenceContractFileInfo record = new EvidenceContractFileInfo();

        record.setUserMasterId(applyInfo.getUserMasterId());
        record.setUserSlaveId(applyInfo.getUserSlaveId());
        record.setBusinessTypeId(applyInfo.getBusinessId());
        record.setEvidenceType(applyInfo.getEvidenceType());

        record.setJsonHash(applyInfo.getContentHash());
        record.setJsonMd5(applyInfo.getContentMd5());
        record.setJsonSha1(applyInfo.getContentSha1());
        record.setJsonSha256(applyInfo.getContentSha256());
        record.setContractUuid(applyInfo.getContractUuid());
        record.setSize(applyInfo.getSize());
        record.setRecordTime(applyInfo.getRecordTime());
        //是否申请出证： 是否申请出证：0未申请，1申请中，2出证中，3出证完成
        record.setIsApplyEvidence(0);
        record.setStoreEvidenceTime(new Date());
        evidenceContractFileInfoMapperCustom.insertSelective(record);
        return record;
    }

    /**
     * 存证表-合同、人和文件关联信息存证接口
     *
     * @param applyInfo
     * @return
     * @author liran
     */
    public EvidenceContractInfo addContractInfo(AddContractInfoForm applyInfo) {
        EvidenceContractInfo record = new EvidenceContractInfo();
        record.setUserMasterId(applyInfo.getUserMasterId());
        record.setUserSlaveId(applyInfo.getUserSlaveId());
        record.setBusinessTypeId(applyInfo.getBusinessId());
        record.setEvidenceType(applyInfo.getEvidenceType());

        record.setJsonHash(applyInfo.getContentHash());
        record.setJsonMd5(applyInfo.getContentMd5());
        record.setJsonSha1(applyInfo.getContentSha1());
        record.setJsonSha256(applyInfo.getContentSha256());
        record.setContractUuid(applyInfo.getContractUuid());
        record.setSize(applyInfo.getSize());
        record.setRecordTime(applyInfo.getRecordTime());
        //是否申请出证： 是否申请出证：0未申请，1申请中，2出证中，3出证完成
        record.setIsApplyEvidence(0);
        record.setStoreEvidenceTime(new Date());
        evidenceContractInfoMapperCustom.insertSelective(record);
        return record;
    }
}
